﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrStatWorkResult.aspx.cs" Inherits="ZX.WebApp.EHR.hrStatWorkResult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>手工统计考勤</title>
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/table_style.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <script src="../Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        var _statType="Emp";
        $(function () {
            $("#txtDeptIds").attr("disabled", true).css("background", "whitesmoke")
            $("#txtEmp").attr("disabled", true).css("background", "whitesmoke")

            //统计类型选择
            $('input:radio[name="statType"]').click(function () {
                _statType = $('input:radio[name="statType"]:checked').val();
                if (_statType == null) {
                    alert("什么也没选中!");
                    return false;
                }
                else {
                    //alert(_statType);
                    if (_statType == "Dept") {
                        $("#btnDeptIds").removeAttr("disabled");
                        $("#btnEmp").attr("disabled", true);
                        $("#txtEmp").val("");
                        $("#Emp").val("");
                    }
                    else {
                        $("#btnEmp").removeAttr("disabled");
                        $("#btnDeptIds").attr("disabled", true);
                        $("#txtDeptIds").val("");
                        $("#DeptIds").val("");
                    }
                }
            })
        })

        function fnStart() {
            //debugger;
            var beginDate = $("#BeginWorkDate").val();
            var endDate = $("#EndWorkDate").val();
            var emp=$("#Emp").val();
            var deptIds=$("#DeptIds").val();

            if (beginDate == "") {
                alert("开始日期为空！");
                return;
            }

            if (endDate == "") {
                alert("结束日期为空！");
                return;
            }

            if(_statType=="Emp" && emp=="") {
                alert("人员为空！");
                return;
            }

            if(_statType=="Dept" && deptIds=="") {
                alert("部门为空！");
                return;
            }

            $("#btnStat").attr("disabled", true);
            $("#spMsg").show();
            $("#spMsg").append("开始统计<br>");
            //开始统计
            ImportBPMQianKa(_statType, beginDate, endDate, deptIds, emp);
        }

        function ImportBPMQianKa(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("导入BPM签卡流程<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=ImportBPMQianKa&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        //debugger;
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            //alert("统计成功!");
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("导入BPM签卡流程失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        ImportWorkBillFromBPM_OVERTIME(_statType, beginDate, endDate, deptIds, emp);
                        //$("#btnStat").attr("disabled", false);
                        //$("#spMsg").append("统计结束<br>");
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        function ImportWorkBillFromBPM_OVERTIME(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("导入BPM加班流程<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=ImportWorkBillFromBPM_OVERTIME&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("导入BPM加班流程失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        ImportWorkBillFromBPM_LEAVE(_statType, beginDate, endDate, deptIds, emp);
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        function ImportWorkBillFromBPM_LEAVE(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("导入BPM请假流程<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=ImportWorkBillFromBPM_LEAVE&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("导入BPM请假流程失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        ImportWorkBillFromBPM_OVERTIMELEAVE(_statType, beginDate, endDate, deptIds, emp);
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
        function ImportWorkBillFromBPM_OVERTIMELEAVE(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("导入BPM调休流程<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=ImportWorkBillFromBPM_OVERTIMELEAVE&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("导入BPM调休流程失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        ImportWorkBillFromBPM_TRIP(_statType, beginDate, endDate, deptIds, emp);
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        function ImportWorkBillFromBPM_TRIP(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("导入BPM出差流程<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=ImportWorkBillFromBPM_TRIP&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("导入BPM出差流程失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        calcremovertimeleave(_statType, beginDate, endDate, deptIds, emp);
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        function calcremovertimeleave(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("累计加班、剩余调休时长<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=calcremovertimeleave&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("累计加班、剩余调休时长失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        //$("#btnStat").attr("disabled", false);
                        //$("#spMsg").append("统计结束<br>");
                        StatWorkResult(_statType, beginDate, endDate, deptIds, emp)
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        function StatWorkResult(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("考勤明细计算<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=statworkresult&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("考勤明细计算失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        ConfirmWorkResult_Calc(_statType, beginDate, endDate, deptIds, emp)
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        function ConfirmWorkResult_Calc(_statType, beginDate, endDate, deptIds, emp) {
            $("#spMsg").append("考勤确认表更新<br>");
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=ConfirmWorkResult_Calc&statType=" + _statType + "&beginDate=" + beginDate + "&endDate=" + endDate + "&deptIds=" + deptIds + "&emp=" + emp, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            $("#spMsg").append(str);
                        }
                        else {
                            $("#spMsg").append("考勤确认表更新失败,请检查<br>");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                        $("#btnStat").attr("disabled", false);
                        $("#spMsg").append("统计结束<br>");
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
     </script>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
        <div>
        <table align="center" class="TableBlock" width="99%" id="tbMain" name="tbMain">
		        <tr>
			        <td align="right" class="TableData" width="200">统计区间</td>
			        <td align="left" class="TableContent">
                        从<input class="td_value3"  id="BeginWorkDate" name="BeginWorkDate" onclick="WdatePicker()" style="width: 120px" type="text" />
                        到
                        <input class="td_value3"  id="EndWorkDate" name="EndWorkDate" onclick="WdatePicker()" style="width: 120px" type="text" />
                    </td>
		        </tr>
		        <tr>
			        <td align="right" class="TableData" width="200">统计方式</td>
			        <td align="left" class="TableContent">
                       <input type="radio" name="statType" value="Emp" checked="checked"/> 按人员
                       <input type="radio" name="statType" value="Dept"/> 按部门
                    </td>
		        </tr>
		        <tr>
			        <td align="right" class="TableData" width="200">选择人员</td>
			        <td align="left" class="TableContent">
                        <input class="td_value3" id="txtEmp" name="txtEmp"  style="width: 200px" type="text" readonly="readonly"/>
                        <input class="td_value3" id="Emp" name="Emp"  style="width: 200px" type="hidden" readonly="readonly"/>
                        <button id="btnEmp" name="emp" type="button">选择</button>
                        <button id="btnSelectEmps" type="button" onclick="fnSelectEmps();" style="display:none">选择多人</button>
                    </td>
		        </tr>
		        <tr>
			        <td align="right" class="TableData" width="200">选择部门</td>
			        <td align="left" class="TableContent">
                        <input class="td_value3" id="txtDeptIds" name="txtDeptIds" style="width: 200px" type="text" readonly="readonly" />
                        <input class="td_value3" id="DeptIds"  name="DeptIds" style="width: 200px" type="hidden" readonly="readonly" />
                        <button id="btnDeptIds" name="D" type="button" disabled="disabled">选择</button>
                    </td>
		        </tr>
		        <tr>
			        <td colspan="2">
                    <input type="button" id="btnStat" value="开始统计" onclick="fnStart();"/>
                    </td>
		        </tr>
        </table>
        </div>
        <div id="spMsg" style="display:none"></div>
        <div id="dialog1" class="yui-pe-content">
            <div class="hd">
                信息选择</div>
            <div class="bd">
                <iframe id="EditUIWindow" frameborder="0" src="" style="width: 100%; height: 100%;
                    margin: 0px; padding: 0px;"></iframe>
            </div>
        </div>
    </form>
</body>
<script type="text/javascript">
    var editlist = "",_CustomerId = "", _State = "0";
    /* 对应的方法和ID*/
    var _fn, _id;
    function ShowDialog(fn, id, src) {
        _fn = fn;
        _id = id;
        document.getElementById("EditUIWindow").src = src;
        YAHOO.example.container.dialog1.show();
    }
    function ShowDialog2(fn, id) {
        _fn = fn;
        _id = id;
        YAHOO.example.container.dialog1.show();
    }

    //选择多人
    var fnSelectEmps = function () {
        document.getElementById("EditUIWindow").src = "../EHR/hrSelectEmps.aspx";
        YAHOO.example.container.dialog1.show();
    }


    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {
        var handleSubmit = function () {
            var editwindow = document.getElementById("EditUIWindow");
            if (editwindow) {
                if (_id == "btnDeptIds" || _id == "btnEmp") {
                    _State = "0";
                    editwindow.contentWindow.ChooseInfo();
                }
            }
            if (_State != "") {
                YAHOO.example.container.dialog1.hide();
            }
        };
        var handleCancel = function () {
            this.cancel();
        };
        var handleSuccess = function (o) {
            var response = o.responseText;
            response = response.split("<!")[0];
            document.getElementById("resp").innerHTML = response;
        };
        var handleFailure = function (o) {
            alert("Submission failed: " + o.status);
        };
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
					        { width: "620px",
					            height: "450px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            close: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "确定", handler: handleSubmit, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
        YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
        YAHOO.example.container.dialog1.render();
        //拖动大小1
        var resize = new YAHOO.util.Resize("dialog1", {
            handles: ["br"],
            autoRatio: false,
            minWidth: 450,
            minHeight: 300,
            status: false
        });
        resize.on("startResize", function (args) {
            if (this.cfg.getProperty("constraintoviewport")) {
                var D = YAHOO.util.Dom;

                var clientRegion = D.getClientRegion();
                var elRegion = D.getRegion(this.element);

                resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
                resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            } else {
                resize.set("maxWidth", null);
                resize.set("maxHeight", null);
            }

        }, YAHOO.example.container.dialog1, true);
        resize.on("resize", function (args) {
            var panelHeight = args.height;
            this.cfg.setProperty("height", panelHeight + "px");
        }, YAHOO.example.container.dialog1, true);
        //拖动大小2
        var resize = new YAHOO.util.Resize("dialog2", {
            handles: ["br"],
            autoRatio: false,
            minWidth: 300,
            minHeight: 250,
            status: false
        });
        resize.on("startResize", function (args) {
            if (this.cfg.getProperty("constraintoviewport")) {
                var D = YAHOO.util.Dom;

                var clientRegion = D.getClientRegion();
                var elRegion = D.getRegion(this.element);

                resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
                resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            } else {
                resize.set("maxWidth", null);
                resize.set("maxHeight", null);
            }

        }, YAHOO.example.container.dialog2, true);
        resize.on("resize", function (args) {
            var panelHeight = args.height;
            this.cfg.setProperty("height", panelHeight + "px");
        }, YAHOO.example.container.dialog2, true);
    });
</script>
</html>
